<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            历史记录
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">仓库</div>
                    <select id="workCenterGid" onchange="onChange()">
                    </select>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">库位</div>
                    <select id="workCellGid">
                    </select>
                </div>
            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <!-- <div class="aui-btn aui-btn-info" style="width:25%;margin-left:6%;" onclick="doSearch()">查询</div> -->
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="doSearch()">查询</div>
        <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;">
            <table class="table" style='width:100%;' id="table">
                <thead>
                    <tr style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 12px;font-weight: bold;">
                        <td algin='center'>序号</td>
                        <td algin='center'>物料号</td>
                        <td algin='center'>批次号</td>
                        <td algin='center'>现有数</td>
                        <td algin='center'>冻结数</td>
                    </tr>
                </thead>
                <tbody id="tbodyHtml">
                </tbody>
            </table>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //初始化
    apiready = function() {

        //查询仓库下拉框
        getComboxWorkCenter();
    }

    //查询仓库下拉框
    function getComboxWorkCenter() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCenter";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                workCenterCode: "",
                mrlCode: "",
                lotCode: "",
                qty: "",
                un:un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == "0") {

                    //仓库list
                    var list = eval(myobj.list);
                    var html = "<option value=''>--请选择--</option>";
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].workCenterGid + "'>" + list[i].workCenterName + "</option>";
                    }
                    $api.html($api.byId("workCenterGid"), html);

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }

            }
        });
    }

    //仓库下拉框值改变
    function onChange() {
        //仓库编码
        var workCenterGid = $("#workCenterGid").val();

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCell";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                flag: "in_rk", //库内库间标识（out_kn库内  out_kj库间，in_rk入库）
                relWorkCellGid: "", //调入库位
                tm: "",
                workCellFlag: "",
                workCenterGid: workCenterGid, //仓库GID
                workCellCode: "",
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == "0") {

                    //仓库list
                    var list = eval(myobj.list);
                    var html = "<option value=''>--请选择--</option>";
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].workCellGid + "'>" + list[i].workCellName + "</option>";
                    }
                    $api.html($api.byId("workCellGid"), html);

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }

            }
        });
    }

    //查询
    function doSearch() {
        //仓库GID
        var workCenterGid = $("#workCenterGid").val();
        //库位GID
        var workCellGid = $("#workCellGid").val();

        //计划日期非空校验
        if (workCenterGid == null || workCenterGid == "" || workCenterGid == undefined) {
            api.toast({
                msg: "请选择仓库",
                duration: 3000
            });
            return;
        }

        //库位非空校验
        if (workCellGid == null || workCellGid == "" || workCellGid == undefined) {
            api.toast({
                msg: "请选择库位",
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/doSearchStock";
        var data = {
            values: {
                workCenterGid: workCenterGid,
                workCellGid: workCellGid,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 12px;'>";
                        html += "<td name='seqno'>" + (i + 1) + "</td>";
                        html += "<td name='mrlCode'>" + list[i].mrlCode + "</td>";
                        html += "<td name='lotCode'>" + list[i].lotCode + "</td>";
                        html += "<td name='qty'>" + list[i].qty + "</td>";
                        html += "<td name='frezzQty'>" + list[i].frezzQty + "</td>";
                        html += "</tr>";
                    }
                    $api.html($api.byId("tbodyHtml"), html);

                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //订单返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
